package gameservice

import (
	"admin100/app/dao/gamedao"
	"admin100/library/define"
	"admin100/library/define/defErr"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
)

var PlayerProp = &playerPropService{}

type playerPropService struct{}

func (s *playerPropService) GetTotalProp(node string, propType int, propId int, channelList []string) int {
	gameDb := gamedao.NewPlayerPropDao(node)
	playerDb := gamedao.NewPlayerDao(node)
	r, err := gameDb.Fields("sum("+gameDb.Columns.Num+")").InnerJoin(playerDb.Table, "T2",
		gameDb.Table+"."+gameDb.Columns.PlayerId+"=T2."+playerDb.Columns.Id).
		Where(g.Map{
			gameDb.Table + "." + gameDb.Columns.PropType: propType,
			gameDb.Table + "." + gameDb.Columns.PropId:   propId,
			"T2." + playerDb.Columns.Channel:             channelList,
		}).Value()
	defErr.IfPanic(err, define.DataOptFail)
	if r == nil {
		return 0
	}

	return gconv.Int(r.Val())
}
